<template>
  <div class="index">
    <div class="center">
      <left></left>
      <div class="right">
        <top></top>
        <div class="hei10"></div>
        <div class="team">
          <div class="powertop">
            <div class="powertopcon">
              <router-link class="powertopli teamlei " to="/callsystem/newcalls/waihuzhongxin">外呼任务</router-link>
              <router-link class="powertopli " to="/callsystem/newcalls/waihuzhongxin/bodajilu">拨打记录</router-link>
            </div>
          </div>
        </div>
        <div class="t_num_nav">
          <div class="t_nav_num_box">
            <img class="t_nav_img" src="../../../../static/img/wh1.png" alt="">
            <div>
              <div class="t_nav_num_title">累计拨打用户数</div>
              <div class="t_nav_num_num">{{ amount }}</div>
            </div>
          </div>
          <div class="t_nav_num_box">
            <img class="t_nav_img" src="../../../../static/img/wh2.png" alt="">
            <div>
              <div class="t_nav_num_title">拨通用户数</div>
              <div class="t_nav_num_num">{{ called_amount }}</div>
            </div>
          </div>
          <div class="t_nav_num_box">
            <img class="t_nav_img" src="../../../../static/img/wh3.png" alt="">
            <div>
              <div class="t_nav_num_title">平均通话时长（s）</div>
              <div class="t_nav_num_num">{{ avg_time }}</div>
            </div>
          </div>
          <div class="t_nav_num_box">
            <img class="t_nav_img" src="../../../../static/img/wh4.png" alt="">
            <div>
              <div class="t_nav_num_title">业务成功率（%）</div>
              <div class="t_nav_num_num">{{ success_rate }}</div>
            </div>
          </div>
        </div>
        <div class="con">
          <div>
            <el-table
            v-loading='loading'
            :header-cell-style="{ 
            background:'#F4F4F4',
            color:'#7D8087'}"
              :data="tableData"
              style="width: 100%;margin-top: 20px;">
              <el-table-column
                prop="title"
                align="center"
                label="任务名称">
              </el-table-column>
              <el-table-column
                prop="type_name"
                align="center"
                label="创建方式">
                <template slot-scope="scope">
                  
                  <span v-if="scope.row.type == 2">导入创建</span>
                  <span v-else-if="scope.row.type == 3">创建营销</span>
                  <span v-else>普通创建</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="class"
                align="center"
                label="任务类型">
              </el-table-column>
              <el-table-column
                prop=""
                align="center"
                label="已拨打/任务总数">
                <template slot-scope="scope">
                  <span>{{ scope.row.called_num }}</span>/<span>{{ scope.row.total_num }}</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="delay_at"
                align="center"
                label="任务截止时间">
                
              </el-table-column>
              <el-table-column
                prop="finish_at"
                align="center"
                label="紧急程度">
                <template slot="header" slot-scope="scope">
                  <div>紧急程度<i class="el-icon-d-caret" style="cursor: pointer;" @click="changeorderby" ></i></div>
                </template>
                <template slot-scope="scope">
                  <span v-if="scope.row.urgency==1" style="color: #ffb487;">较高</span>
                  <span v-else-if="scope.row.urgency==2" style="color: #f83d49;">最高</span>
                  <span v-else>普通</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="finish_at"
                align="center"
                label="操作">
                
                <template slot-scope="scope">
                  <el-button type="danger" style="background-color: #2974FF;" round @click="toCallOrder(scope.row)">订单外呼
                  </el-button>
                  <el-button type="text"   @click="shifang(scope.row)">释放预占
                  </el-button>
                </template>
              </el-table-column>
             
            </el-table>
            <div style="text-align: right;margin-top: 20px;">
              <el-pagination
                @current-change="changepage"
                background
                :page-size="searchform.pageSize"
                layout="total,prev, pager, next"
                :total="total">
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
    </div>
    
  </div>
</template>

<script>
  import axios from "axios";
  import top from '@/components/top.vue'
  import left from '@/components/left.vue'
  import foot from '@/components/foot.vue'
  import robot from '@/components/robot.vue'
  import UploadExcelComponent from "@/components/UploadExcel/index3.vue";

  export default {
    components: {
      "left": left,
      "top": top,
      'foot': foot,
      "robot":robot,
      UploadExcelComponent
    },
    name: 'quanyi',
    data() {
      return {
        
        shopid:'',
        searchform:{
          urgency:'',
          page:1,
          pageSize:20,
          order_by:''
        },
        tableData: [],
        total:1000,
        loading: false,
        amount:0,
        called_amount:0,
        avg_time:0,
        success_rate:0,

      }
    },
    created() {
      //店铺权限问题
			this.shopid = JSON.parse(localStorage.getItem('SHOP')).shop_id;
      //列表
      this.getlist()
      //统计
      this.getnum()
    },
    methods: {
      change:function(){
        this.getlist()
      },
      //统计
      getnum(){
        axios.get('/api/plan-market/call/data/v2')
          .then((response) => {
            if (response.data.msg.code == 0) {
              console.log('统计')
              console.log(response)
              this.amount =  response.data.data.amount
              this.called_amount = response.data.data.called_amount
              this.avg_time = response.data.data.avg_time
              this.success_rate = response.data.data.success_rate
              
            } else {
              this.$message.error(response.data.msg.info);
            }
          })
      },
      //列表
      getlist(){
        this.loading = true
        axios.get('/api/plan-market/call/task/center/v2?urgency='+this.searchform.urgency+'&page='+this.searchform.page+'&page_size='+this.searchform.pageSize+'&order_by='+this.searchform.order_by)
          .then((response) => {
            if (response.data.msg.code == 0) {
              console.log('列表')
              console.log(response)
              this.tableData = response.data.data.data
              this.total = response.data.data.total
            } else {
              this.$message.error(response.data.msg.info);
            }
            this.loading = false
          })
      },
      //翻页
      changepage(val){
        console.log(val)
        this.searchform.page = val
        this.getlist()
      },
      toCallOrder(row){
        this.$router.push({
          path: "/callsystem/newcalls/waihuzhongxin/waihuorder",
          query: { id: row.id,title:row.title,called_num:row.called_num,total_num:row.total_num,type:row.type }
        });
      },
      // 排序
      changeorderby(){
        if(this.searchform.order_by==''){
          this.searchform.order_by = 1
        }else if(this.searchform.order_by==1){
          this.searchform.order_by = 0
        }else if(this.searchform.order_by==0){
          this.searchform.order_by = 1
        }
        this.searchform.page = 1
        this.getlist()

      },
      shifang(row){
        this.$confirm('是否确认释放预占?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {

          axios.get('/api/plan-market/call/order/release/all/v2?task_id='+row.id)
          .then((response) => {
            if (response.data.msg.code == 0) {
              this.$message({
                type: 'success',
                message: '操作成功!'
              });
            } else {
              this.$message.error(response.data.msg.info);
            }
            
          })
          
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });          
        });
      }
      
    },
    beforeDestroy(){
     
    },
    
    
  }
</script>

<style  scoped>

    .t_dr_btn{
        text-align: center;
        width: 160px;
        background-color:#2974FF;
        border-radius: 4px;
    }
    /deep/ .t_dr_btn .el-button--text{
      color: white;
    }

    .team {
      background: #F9F9F9;
    }

    .powertop {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .powertopcon {
      display: flex;
      
    }
    .t_jqr_box{
      background-color: #007EFF;
      color: white;
      font-size: 14px;
      display: flex;
      align-items: center;
      justify-content: center;
      height: 32px;
      width: 160px;
      margin-right: 30px;
      border-radius: 3px;
      cursor: pointer;

    }
    .powertopli {
      width: 180px;
      color: #727272;
      font-size: 16px;
      text-align: center;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      padding-top: 20px;
    }
    .powertopli_lei{
      background-color: white;
      color: #2974FF;
    }
    .t_under_line{
      width: 20px;
      height: 4px;
      background-color:#F9F9F9 ;
      border-radius: 4px;
      margin-top: 10px;
    }
    .t_under_line_lei{
      
      background-color:#2974FF ;
     
    }
    .powertopact {
      background: #FFFFFF;
      border-bottom: 3px #2974FF solid;
      color:#2974FF ;
    }

    .piliang {}

    .piliangxuan {
      padding: 3px 0;
    }

    .mesquanxuan {
      padding: 10px 30px 20px 0px;
      display: flex;
      font-size: 14px;
      background: #f4f4f4
    }
    .con {
				padding: 20px ;
    }
    .t_overtips{
      width: 100%;
      overflow: hidden;        /*内容会被修剪，并且其余内容是不可见的*/
      text-overflow:ellipsis;  /*显示省略符号来代表被修剪的文本。*/
      white-space: nowrap;     /*文本不换行*/
    }
    .t_tongji_box{
      background-color: rgb(241, 241, 241);
      padding: 16px 30px;
      box-sizing: border-box;
      /* font-size: 18px; */
      display: flex;
      color: #515151;
      margin-top: 20px;
      margin-bottom: 20px;
    }
    .t_title_box{
      display: flex;
      align-items: center;
      color: #525252;
      margin-bottom: 10px;
      margin-top: 20px;
    }
    .t_red_g{
      background-color: #2974FF;
      width: 4px;
      height: 16px;
      margin-right: 10px;
    }
    .t_red_time{
      color: #2974FF;
    }
    .t_search_input{
      width: 191px;
      margin-bottom: 5px;
    }
    /* .t_search_box{
      display: flex;
      flex-wrap: wrap;
    } */
    /deep/.t_search_box .el-input--suffix .el-input__inner  {
      background-color: #f7f8fa;
      border: none;
    }
    /deep/.t_search_box .el-range-editor.el-input__inner{
      background-color: #f7f8fa;
      border: none;
    }
    /deep/.t_search_box .el-date-editor .el-range-input{
      background-color: #f7f8fa;
      border: none;
    }
    /deep/.t_search_box .el-input__inner{
      background-color: #f7f8fa;
      border: none;
      
    }
    /deep/ .el-pagination.is-background .btn-prev:disabled{ background: rgba(246, 246, 246, 0.3); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .el-pagination.is-background .btn-next:disabled{ background: rgba(246, 246, 246, 0.3); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/ .el-pagination.is-background .btn-next{ background: rgba(246, 246, 246,1); border: 1px rgba(167, 167, 167,1) solid;}
    /deep/ .el-pagination.is-background .btn-prev{ background: rgba(246, 246, 246,1); border: 1px rgba(167, 167, 167,1) solid;}
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active{ background-color: #2974FF;}
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active:hover {
        color: #fff;
    }
    /deep/ .el-pagination.is-background .el-pager li:not(.disabled):hover {
        color: #2974FF;
    }
    /deep/.index .el-pager li{ border-radius: 14px; background: rgba(255, 255, 255, 1); border: 1px rgba(167, 167, 167, 0.3) solid;}
    /deep/.index .btn-prev{ border-radius: 14px; padding: 0 10px;}
    /deep/.index .btn-next{ border-radius: 14px; padding: 0 10px;}

    /deep/.el-table th:last-child{
      padding: 0;
    }

    .team .powertopli {
    	flex-basis: 180px;
    	line-height: 50px;
    	border-bottom: 3px #F9F9F9 solid;
    	color: #727272;
    	border-right: 1px #F9F9F9 solid;
    	font-size: 16px;
    	text-align: center;
      padding-top: 0;
    }
    .team .teamlei {
    	background: #FFFFFF;
    	border-bottom: 3px #2974FF solid;
    }
    /deep/.t_imp_select .el-input__inner{
      border-color: white;
      border-radius: 10px;
    }
    /deep/.t_imp_select .el-input__suffix{
      right: 11px;
    }
    .t_nav_num_box{
      display: flex;
      margin-right: 100px;
      align-items: center;
    }
    .t_nav_img{
      width: 70px;
      height: 70px;
      margin-right: 16px;
    }
    .t_nav_num_title{
      color: #8A8A8A;
      font-size: 12px;
    }
    .t_nav_num_num{
      color: #333333;
      font-size: 36px;
      margin-top: 5px;
    }
    .t_num_nav{
      display: flex;
      padding: 40px 20px 0px 20px;

    }
    .el-button--danger:hover{
      background-color: #2974FF;
    }
</style>
